//快排3 代码量小一些
function quickSort3(arr){
    function quickSort(arr,left,right){
        let l = left
        let r = right
        if(l>=r) return
        while(l < r){
            while(arr[l] <= arr[r] && l < r){
                l++
            }
            swap(arr,l,r)

            while(arr[l] <= arr[r] && l < r){
                r--
            }
            swap(arr,l,r)
        }
        let middle = r //取中间值
        quickSort(arr,left,middle-1)
        quickSort(arr,middle,right)
    }
    quickSort(arr,0,arr.length-1)
}

function swap(arr,i,j){ //用于交换的函数
    let temp = arr[i]
    arr[i] = arr[j]
    arr[j] = temp
}

let arr3 = [3,5,2,1,0,9,8,6,4,7]
console.log(arr3)
quickSort3(arr3)
console.log(arr3)

function quickSort3(arr){
    function quickSort(arr,left,right){
        let l = left;
        let r = right;
        if(l>=r) return;
        while(l<r){
            while(arr[l]<=arr[r]&&l<r){
                l++;
            }
            swap(arr,l,r);
            while(arr[l]<=arr[r]&&l<r){
                r--;
            }
            swap(arr,l,r);
        }
        let middle = r;
        quickSort(arr,left, middle-1);
        quickSort(arr,middle,right);
    }
    quickSort(arr,0,arr.length-1);
}
function swap(arr,i,j){ //用于交换的函数
    let temp = arr[i]
    arr[i] = arr[j]
    arr[j] = temp
}

let arr3 = [3,5,2,1,0,9,8,6,4,7]
console.log(arr3)
quickSort3(arr3)
console.log(arr3)